#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include "../utils/conn.h"

int main(int argc, char* argv[]) {
    HTTP_REQUEST req={0};
    memset(&req,0,sizeof(HTTP_REQUEST));
   
    // Initialize request
    strcpy(req.method,"GET");
    strcpy(req.url,"/");
    strcpy(req.version,"HTTP/1.1");
    strcpy(req.headers,"Host: www.baidu.com\r\nConnection: keep-alive\r\nHTTP2-Settings: \r\n");
    // send HTTP request
    int client_socket = connect_to(argv[1], SOCK_STREAM, 10);
    if (client_socket<0) {
        printf("Failed to connect to server\n");
        return 1;
    }
    send_http_request(client_socket,&req,NULL,0);
    // receive HTTP response
    printf("Received HTTP response from %s\n",req.url); 
    HTTP_RESPONSE res={0};
    memset(&res,0,sizeof(HTTP_RESPONSE));
    recv_http_response(client_socket,&res,NULL);
    printf("Received HTTP response from %s\n",req.url);     
    //printf("[vsersion]: %s\n[status_code]: %d\n[status_msg]: %s\n[headers]:\n%s\n",res.version,res.status_code,res.status_msg,res.headers);
    return 0;
}